package ventanas;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextArea;
import javax.swing.JCheckBox;
import javax.swing.JScrollPane;

public class Alerta extends JDialog {

	private final JPanel contentPanel = new JPanel();
	int contador;
	private JCheckBox chckbxNewCheckBox ;
	JTextArea textArea;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Alerta dialog = new Alerta();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Alerta() {
		setBounds(100, 100, 450, 665);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contador=0;
		contentPanel.setLayout(null);
		
		chckbxNewCheckBox = new JCheckBox("Activo");
		chckbxNewCheckBox.setSelected(true);
		chckbxNewCheckBox.setBounds(0, 568, 84, 23);
		contentPanel.add(chckbxNewCheckBox);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 0, 442, 561);
		contentPanel.add(scrollPane);
			
		textArea = new JTextArea();
		scrollPane.setViewportView(textArea);
			
		
		
		
		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
		getContentPane().add(buttonPane, BorderLayout.SOUTH);
		JButton okButton = new JButton("OK");
		okButton.setActionCommand("OK");
		buttonPane.add(okButton);
		getRootPane().setDefaultButton(okButton);
			
		JButton cancelButton = new JButton("Cancel");
		cancelButton.setActionCommand("Cancel");
		buttonPane.add(cancelButton);
			
		
	}
	public void anadeMensaje(String msg_){
		//contenedor.setText(contenedor.getText()+"\r\n"+String.valueOf(contador++)+msg_);
		if(chckbxNewCheckBox.isSelected())
		{
			textArea.append(String.valueOf(contador++)+msg_+"\r\n");
			if(contador>20){
				textArea.removeAll();
				contador=0;	
			}
		
		}
		
	}
}
